package com.lemox.thread;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.security.NoSuchAlgorithmException;

import com.lemox.security.RSAGenrator;

public class TCPServerThread extends Thread
{
	public Socket socket;
	public RSAGenrator gen;
	
	public TCPServerThread(){}
	
	public void run ()
	{
		try {
			System.out.print(socket.getInetAddress().toString() + ":");
			System.out.println(socket.getPort());
			gen = new RSAGenrator();
			gen.generate_rsa_key();
			
			System.out.println("Public Key:");
			System.out.println(gen.public_key.getPublicExponent());
			System.out.println(gen.public_key.getModulus());
			
			System.out.println("Private Key:");
			System.out.println(gen.private_key.getPrivateExponent());
			System.out.println(gen.private_key.getModulus());
			
			OutputStream out = socket.getOutputStream();
			out.write(gen.public_key.getModulus().toString().getBytes());
			
			
			InputStream in = socket.getInputStream();
			int len = 0;
			byte[] b = new byte[1024];
			len = in.read(b);
			
			System.out.println(new String(b));
			
			
			
			
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
	}
}
